package cn.restcloud.example.controller;

import org.bson.Document;
import cn.restcloud.framework.core.annotation.bean.*;
import cn.restcloud.framework.core.annotation.rest.*;
import cn.restcloud.framework.view.base.DocAndView;
import cn.restcloud.framework.view.util.ViewUtil;
import cn.restcloud.framework.core.util.db.rdb.*;

/**
 * 执行SQL进行认证
 * 这个接口需要勾上允许匿名用户访问
 * @author cn.restcloud
 *
 */
@BeanConfig(appId = "example",beanId = "UserAuthenticationRest",beanName = "用户认证接口示例",beanType = BeanType.CONTROLLER)
@RestConfig(url = "/rest/example/users")
public class UserAuthenticationRest {

	@RestConfig(configName = "用户名及密码认证服务示例",method = MethodType.POST,url = "/authentication")
	@Params({
		@Param(id = "userId", name = "用户名",required=true),
		@Param(id = "password", name = "密码",required=true)
	})
	public DocAndView authenticationUserAndPassword(String userId,String password) throws Exception{
		String sql="select * from jsxxb where jsbh=? and password=?";
		Document doc=RdbUtil.getDoc(RdbUtil.getConnection("gypjtmp"),sql,userId,password);
		if(doc==null){
		    return ViewUtil.getErrorView("用户名或密码错误!");
		}else{
		    return ViewUtil.getSuccessView("认证成功");
		}
	}
	
	
}
